package com.niit.covid.sum;


import com.niit.covid.bean.CovidCountBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author:Ys
 * @date: 2022年08月11日 14:07
 * @desc:
 */
public class CovidSumReducer extends Reducer<Text, CovidCountBean,Text,CovidCountBean> {
    CovidCountBean outvalue = new CovidCountBean();

    @Override
    protected void reduce(Text key, Iterable<CovidCountBean> values, Context context) throws IOException, InterruptedException {
        /**
         * 创建统计变量
         */
        long totalCases = 0;//累计确诊人数
        long totalDeaths = 0;//累计死亡人数

        /**
         * 遍历该州的各个县的数据
         */
        for (CovidCountBean value : values) {
            totalCases += value.getCases();  //
            totalDeaths += value.getDeaths();
        }

        /**
         * 输出结果赋值
         */
        outvalue.set(totalCases,totalDeaths);
        context.write(key,outvalue);

    }
}
